function changeNum(obj,id,price) {
	var num = document.getElementsByName('num')[obj.title];
	var total_small = [];
	var total_small_t = [];
	var warning = [];
	var flowsub = document.getElementById('flow');
	for(var i =0,td=document.getElementsByTagName('td');i<td.length;i++) {
		if(td[i].className == 'sprice'){
			total_small.push(td[i]);
			total_small_t.push(td[i]);
		}
	}
	for(var i =0,span=document.getElementsByTagName('span');i<span.length;i++) {
        if(span[i].className == 'warning'){
            warning.push(span[i]);
        }
    }
    var warning2 = warning[obj.title];
	var total_small2 = total_small[obj.title];
	var total = document.getElementById('total');
	var totalV = 0;
	if(isNaN(num.value) || num.value == 0) num.value = 1;
	ajax({
		'url':'?a=cart&m=changeNum',
		'method':'post',
		'async':false,
		'data':{
			'num':num.value,
			'id':id,
			'price':price
		},
		'success':function(text) {
			total_small2.innerHTML = text+'元';
			for(var i=0;i<total_small_t.length;i++) {
				totalV += parseInt(total_small_t[i].innerHTML);
			}
			total.innerHTML = totalV;
		}
	});
	warning2.style.display = 'none';
	ajax({
		'url':'?a=cart&m=isNoMore',
		'method':'post',
        'async':false,
        'data':{
            'num':num.value,
            'aid':id,
        },
        'success':function(text) {
            if(text == 1) {
            	warning2.style.display = 'block';
            	num.value = 1;
            } else {
            	flowsub.onclick = function() {
                    return true;
                }
            }
        }
	});
}

function checkCartIsNull() {
	var t_cart = document.getElementById('t_cart');
	
	if(t_cart.value == '') {
		alert('购物车空空的，请先添加点商品到购物车再结算吧~~');
		return false;
	}
	return true;
}

window.onload = function() {
	var aid = document.getElementsByName('id');
	var num = document.getElementsByName('num');
	var warning = [];
	var flowsub = document.getElementById('flow');
	for(var i =0,span=document.getElementsByTagName('span');i<span.length;i++) {
        if(span[i].className == 'warning'){
            warning.push(span[i]);
        }
    }
    flowsub.onclick = function() {
    	return true;
    }
    for(var i=0;i<aid.length;i++) {
	    var nowNum = num[i].value;
	    var nowAid = aid[i].value;
	    var nowWarning = warning[i];
	    nowWarning.style.display = 'none';
	    ajax({
	        'url':'?a=details&m=isNoMore',
	        'async':false,
	        'method':'post',
	        'data':{
	            'num':nowNum,
	            'aid':nowAid
	        },
	        'success':function(text) {
	            if(text == 1) {
	                nowWarning.style.display = 'block';
	                flowsub.onclick = function() {
                        return false;
                    }
	            }
	        }
	    });
    }
}









